import 'package:acgn_pioneer/models/mobile_bind_model.dart';

import '../public.dart';

class UserService {
  static getUserInfoByToken(String accessToken) async {
    return ACGN.http.fetch(ACGN.config.interfaceApi.getuserinfobytoken,
        isParse: false,
        headers: {'access-token': accessToken}).then((res) async {
      await SpUtil.putObject('userInfo', res);
      UserModel userInfo = UserModel.fromJson(res);
      return userInfo;
    });
  }

  static getUserToken(Map<String, dynamic> queryParameters) {
    return ACGN.http.fetch<UserTokenModel>(
        ACGN.config.interfaceApi.getusertoken,
        queryParameters: queryParameters);
  }

  static Future verifyinvite(Map<String, dynamic> data) {
    return ACGN.http.fetch(ACGN.config.interfaceApi.verifyinvite,
        data: data, method: 'post');
  }

  // 获奖通知
  static Future<PrizeNoticeModel> getPrizeNotice() {
    return ACGN.http
        .fetch(ACGN.config.interfaceApi.shareGetprizenotice, isParse: false)
        .then((res) {
      return PrizeNoticeModel.fromList(res);
    });
  }

  // 邀请码
  static Future<InviteInfoModel> getInviteInfo() {
    return ACGN.http
        .fetch(ACGN.config.interfaceApi.spreadGetinviteinfo, isParse: false)
        .then((res) {
      return InviteInfoModel.fromJson(res);
    });
  }

  // 用户记录
  static Future<dynamic> getUserRecord() async {
    return ACGN.http.fetch<UserRecordModel>(
        ACGN.config.interfaceApi.getuserrecord,
        queryParameters: {'t': DateTime.now().millisecondsSinceEpoch},
        headers: {'cache-control': 'no-cache'});
  }

  static Future<dynamic> deleteUserRead(Map<String, dynamic> data) {
    return ACGN.http.fetch(ACGN.config.interfaceApi.deluserread,
        data: data, method: 'post');
  }

  static Future<dynamic> deleteUserCollect(Map<String, dynamic> data) {
    return ACGN.http.fetch(ACGN.config.interfaceApi.setusercollect,
        data: data, method: 'post');
  }

  // 用户积分账户
  static Future<dynamic> getUserAccount() {
    return ACGN.http
        .fetch<UserAccountModel>(ACGN.config.interfaceApi.userAccount);
  }

  // 提现配置
  static Future<dynamic> getUserCashopt(String token) {
    return ACGN.http
        .fetch(ACGN.config.interfaceApi.userCashopt, isParse: false);
  }

  // 额度明细列表
  static Future<dynamic> getUserLimit(Map<String, dynamic> queryParameters) {
    return ACGN.http.fetch<UserLimitModel>(ACGN.config.interfaceApi.userLimit,
        queryParameters: queryParameters);
  }

  // 积分明细列表
  static Future<dynamic> getUserScore(Map<String, dynamic> queryParameters) {
    return ACGN.http.fetch<UserScoreModel>(ACGN.config.interfaceApi.userScore,
        queryParameters: queryParameters);
  }

  // 提现明细列表
  static Future<dynamic> getUserWithdrawdetail(
      Map<String, dynamic> queryParameters) {
    return ACGN.http.fetch<UserWithdrawModel>(
        ACGN.config.interfaceApi.userWithdrawdetail,
        queryParameters: queryParameters);
  }

  // 额度提现
  static Future<dynamic> userWithdraw(Map<String, dynamic> queryParameters) {
    return ACGN.http.fetch(ACGN.config.interfaceApi.userWithdraw,
        queryParameters: queryParameters, isParse: false);
  }

  // 用户绑定信息
  static Future<dynamic> spreadRealnamestatus(String userId) {
    return ACGN.http.fetch(ACGN.config.interfaceApi.getuserbindinfo,
        method: 'post', data: {'userId': userId}, isParse: false);
  }

  // 用户实名认证信息
  static Future<dynamic> idauthRealNameInfo(String token) {
    return ACGN.http
        .fetch(ACGN.config.interfaceApi.idauthRealnameinfo, isParse: false);
  }

  // 查询用户是否领取过新用户红包
  static Future<dynamic> newUserGift(Map<String, dynamic> queryParameters) {
    return ACGN.http.fetch(ACGN.config.interfaceApi.newusergift,
        queryParameters: queryParameters, isParse: false);
  }

  // 领取新用户红包奖励
  static Future<dynamic> getNewUserGift(String token) {
    return ACGN.http
        .fetch(ACGN.config.interfaceApi.getnewusergift, isParse: false);
  }

  // 发送sms
  static Future<dynamic> sendsms(Map<String, dynamic> data) {
    return ACGN.http
        .fetch(ACGN.config.interfaceApi.sendsms,
            data: data, method: 'post', isParse: false, hasStatus: true)
        .then((res) {
      if (res['status'] == 1031) {
        res['data'] = SmsCodeModel.fromJson(res['data']);
      } else {
        res['data'] = null;
      }
      return res;
    });
  }

  // 绑定手机mobilebind
  static Future<dynamic> mobilebind(Map<String, dynamic> data) {
    return ACGN.http
        .fetch(ACGN.config.interfaceApi.mobilebind,
            data: data, method: 'post', isParse: false, hasStatus: true)
        .then((res) {
      if (res['status'] == 0) {
        res['data'] = MobileBindModel.fromJson(res['data']);
      }
      return res;
    });
  }
}
